<template>
    <div class="content_panel project_modules">
        <div class="content_panel_top">
            <h3 class="panel_title">
                <span>{{$t('collection.amountRemitRecord')}}</span>
            </h3>
            <el-form ref="form" :model="form" :rules="rules" :inline="false" class="module_form">
                <el-row>
                    <el-col :span="4">
                        <el-form-item prop="orderId">
                            <el-input v-model="form.orderId" :placeholder="$t('common.innerOrderId')" clearable></el-input><!--内部订单号-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="phone">
                            <el-input v-model="form.phone" :placeholder="$t('common.mobileNumber')"> clearable></el-input><!--手机号码-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="name">
                            <el-input v-model="form.userName" :placeholder="$t('common.name')" clearable></el-input><!--姓名-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="derateType">
                            <el-select v-model="form.derateType" clearable :placeholder="$t('common.remitType')" style="width: 100%"><!--减免类型-->
                                <el-option key="0" :label="$t('common.validityRemit')" value="0"><!--有效期减免--></el-option>
                                <el-option key="1" :label="$t('common.foreverRemit')" value="1"><!--永久性减免--></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="productChannel" label="">
                            <el-input v-model="form.productChannel" :placeholder="$t('common.applicationMarket')" clearable></el-input><!--应用市场-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="source" label="">
                            <el-input v-model="form.source" :placeholder="$t('common.applyChannel')" clearable></el-input><!--申请渠道-->
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="4">
                        <el-form-item prop="appName" label="">
                            <select-app-list v-model="form.appName" :placeholder="$t('system.appName')"></select-app-list><!--app名称-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="appVersion" label="">
                            <el-input v-model="form.appVersion" :placeholder="$t('common.versionName')" clearable></el-input><!--版本号-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="appPackage" label="">
                            <el-input v-model="form.appPackage" :placeholder="$t('system.appPackage')" clearable></el-input><!--app包名-->
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item prop="applyTime" style="width: 100%"><!--申请时间-->
                            <el-date-picker
                                    v-model="form.applyTime"
                                    type="datetimerange"
                                    format="yyyy-MM-dd HH:mm:ss"
                                    value-format="timestamp"
                                    :editable="false"
                                    style="width: 100%;"
                                    range-separator="-"
                                    :default-time="['00:00:00', '23:59:59']"
                                    :start-placeholder="$t('common.applyStartTime')"
                                    :end-placeholder="$t('common.applyEndTime')"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-button @click="search" type="primary">{{ $t('common.search') }}</el-button>
                        <el-button @click="exportData" type="primary">{{ $t('common.export') }}</el-button>
                    </el-col>
                </el-row>
                <el-row>
                <!-- 伪名 -->
                <el-col :span="4">
                    <el-form-item prop="whiteProductName" v-if="domain == 'Bene'"> <!---->
                        <el-input v-model="form.whiteProductName" :placeholder="$t('common.productName')" clearable><!----></el-input>
                    </el-form-item>
                    <el-form-item prop="kana" v-else> <!--姓名-->
                        <select-kana-list v-model="form.kana" :multiple="false" :placeholder="$t('finance.pseudonym')"></select-kana-list><!--app名称-->
                    </el-form-item>
                </el-col>
                </el-row>
            </el-form>
        </div>

        <div class="module_content">
            <div class="content_panel project_modules">
                <div class="table_list">
                    <el-table ref="table" :data="tableData" style="width: 100%;" tooltip-effect="light" :max-height="tableMaxHeight" :highlight-current-row="true">
                        <el-table-column prop="derateId" :label="$t('common.remitApplyId')" min-width="160"></el-table-column><!--减免申请编号-->
                        <el-table-column prop="orderId" :label="$t('common.innerOrderId')" min-width="180"></el-table-column><!--内部订单号-->
                        <el-table-column prop="userName" :label="$t('common.borrowerName')" min-width="150"></el-table-column><!--借款人姓名-->
                        <el-table-column prop="phone" :label="$t('common.borrowerMobile')" min-width="140"></el-table-column><!--借款人手机号-->
                        <el-table-column prop="derateApplyTime" :label="$t('common.applyDate')" min-width="160"><!--申请时间-->
                            <template slot-scope="{ row }">{{ row.derateApplyTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
                        </el-table-column>

                        <el-table-column prop="totalPeriods" v-if="showSpread" :label="$t('install.totalBorrowPeriod')" min-width="150"></el-table-column><!--借款总周期-->
                        <el-table-column prop="currentPeriod" v-if="showSpread" :label="$t('install.currentBorrowPeriod')" min-width="150"></el-table-column><!--借款当前周期-->

                        <el-table-column prop="derateAmount" :label="$t('common.remitAmount')" min-width="100"><!--减免金额-->
                            <template slot-scope="{ row }">{{ row.derateAmount | formatCurrency }}</template>
                        </el-table-column>
                        <el-table-column prop="teamName" :label="$t('common.overduePeriod')" min-width="90"></el-table-column><!--逾期阶段-->
                        <el-table-column prop="derateType" :label="$t('common.remitType')" min-width="120"><!--减免类型-->
                            <template slot-scope="{ row }">{{ row.derateType | switchDerateType }}</template>
                        </el-table-column>
                        <el-table-column prop="collectionUserName" :label="$t('common.applyPerson')" min-width="120"></el-table-column><!--申请人-->
                        

                        <el-table-column prop="reason" :label="$t('common.applyReason')" :show-overflow-tooltip="true" min-width="180"></el-table-column><!--申请理由-->
                        <el-table-column prop="validiteTime" :label="$t('common.validityPeriod')" min-width="180"><!--有效期-->
                            <template slot-scope="{ row }">{{ row.validiteTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
                        </el-table-column>
                        <el-table-column prop="collectionAuditTime" :label="$t('common.colReviewTime')" min-width="180"><!--催收审核时间-->
                            <template slot-scope="{ row }">{{ row.collectionAuditTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
                        </el-table-column>
                        <el-table-column prop="collectionAuditor" :label="$t('common.colReviewPerson')" min-width="140"></el-table-column><!--催收审核人-->
                        <el-table-column prop="financialAuditTime" :label="$t('common.finReviewTime')" min-width="160"><!--财务审核时间-->
                            <template slot-scope="{ row }">{{ row.financialAuditTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
                        </el-table-column>
                        <el-table-column prop="derateResult" :label="$t('common.reviewResult')" min-width="160"><!--审核结果-->
                            <template slot-scope="{ row }">{{ row.derateResult | switchDerateResults }}</template>
                        </el-table-column>
                        <el-table-column prop="collectionRemark" :show-overflow-tooltip="true" :label="$t('common.colRemark')" min-width="180"></el-table-column><!--催收备注-->
                        <el-table-column prop="financialRemark" :show-overflow-tooltip="true" :label="$t('common.finRemark')" min-width="180"></el-table-column><!--财务备注-->
                        <el-table-column prop="usageStatus" :label="$t('common.usedStatus')" min-width="140"><!--使用状态-->
                            <template slot-scope="{ row }">{{ row.usageStatus | switchUsageStatus }}</template>
                        </el-table-column>
                        <el-table-column align="left" :label="$t('common.applicationMarket')" prop="productChannel" width="130"></el-table-column><!--应用市场-->
                        <el-table-column :label="$t('common.applyChannel')" prop="source" min-width="130"></el-table-column><!--申请渠道-->
                        <el-table-column :label="$t('system.appName')" prop="appName" min-width="130">
                            <template slot-scope="{ row }">{{ row.appName | switchAppName }}</template>
                        </el-table-column><!--APP名称-->
                        <el-table-column v-if="domain=='Bene'" :label="$t('finance.productName')" prop="whiteProductName" min-width="130"></el-table-column><!--伪名-->
                        <el-table-column v-else :label="$t('finance.pseudonym')" prop="kana" min-width="130">
                            <template slot-scope="{ row }">{{ row.kana | switchProductName }}</template>
                        </el-table-column><!--伪名-->

                        <el-table-column :label="$t('common.versionName')" prop="appVersion" min-width="130"></el-table-column><!--版本号-->
                        <el-table-column :label="$t('system.appPackage')" prop="appPackage" min-width="130"></el-table-column><!--APP包名-->
                    </el-table>
                    <!--分页组件-->
                    <pagination @pageChange="pageChange" :page="page"><!--分页组件--></pagination>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import Pagination from '@/components/pagination';
    import mixin from '@/service/mixin';
    import SelectAppList from '@/components/select-app-list';
    import {domain} from '@/config/'
    import SelectKanaList from '@/components/select-kana-list';

    let that = null;
    export default {
        name: 'collection-amountRemit-recordList',
        components: {
            Pagination,
            SelectAppList,
            SelectKanaList
        },
        mixins: [mixin],
        data() {
            return {
                domain:'',
                showSpread:false,
                tableData: [],
                form: {
                    orderId: '',
                    phone: '',
                    userName: '',
                    derateType: '',
                    source: '',
                    appName: '',
                    kana:'',
                    whiteProductName:'',
                    appVersion: '',
                    appPackage: '',
                    applyTime: [],
                },
                rules: {
                    orderId: [
                        {pattern: /^\d+$/, message: this.$t('verify.plsInputNumber')},
                    ],
                    phone: [
                        {pattern: /^\d+$/, message: this.$t('verify.plsInputNumber')},
                    ],
                },
            };
        },
        methods: {
            // 获取列表数据
            getTableData(page = this.page) {
                const params = this.fillParams(page);
                this.$api.collection.queryAuditRecordOfAmountDeduction(params).then(res => {
                    const {status, data, error} = res;
                    if ('1' === status && '00000000' === error && data) {
                        this.tableData = data.resultData;
                        this.setPage(data.page, this.page);
                    }
                    this.tableMaxHeight = document.body.clientHeight - 240;
                });
            },
            // 配置查询和导出参数
            fillParams(page = this.page) {
                const form = this.form;
                const params = {
                    orderId: '',
                    phone: '',
                    userName: '',
                    derateType: '',
                    source: '',
                    appName: '',
                    kana:"",
                    whiteProductName:'',
                    appVersion: '',
                    appPackage: '',
                    derateApplyTimeStart: '',
                    derateApplyTimeEnd: '',
                    page: {
                        pageNo: page.currentPage,
                        pageSize: this.page.pageSize
                    }
                };
                Object.keys(form).forEach(key => {
                    if (typeof form[key] === 'string' && form[key]) {
                        form[key] = form[key].trim();
                        params[key] = form[key];
                    }
                });
                if (form.applyTime && form.applyTime.length >= 2) {
                    params.derateApplyTimeStart = form.applyTime[0];
                    params.derateApplyTimeEnd = form.applyTime[1];
                }
                return params;
            },
            search() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.page.currentPage = 1;
                        this.getTableData();
                    }
                })
            },
            exportData() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        const params = this.fillParams();
                        const user = this.$storage.get('user');
                        const language = this.$storage.getLocal('language');
                        params.language = language;
                        params.token = user.token;
                        params.source = encodeURIComponent(params.source); //针对特殊渠道转码
                        const {$apiConf} = this;
                        const url = this.$urlUtil.fillParams(params, $apiConf.baseUrl + $apiConf.urlType.collection.exprotAuditRecordOfAmountDeductionExcel, ['page']);
                        this.$openNewBlank(url);
                    }
                })
            },
        },
        filters: {
            //金额减免类型
            switchDerateType(type) {
                switch (type + '') {
                    case '0':
                        return that.$t('common.validityRemit');// 有效期减免
                    case '1':
                        return that.$t('common.foreverRemit');// 永久性减免
                    default:
                        return '';
                }
            },
            //审核结果
            switchDerateResults(result) {
                switch (result + '') {
                    case '0':
                        return that.$t('common.finReviewing');// 财务审核中
                    case '1':
                        return that.$t('common.finReviewRefuse');// 财务审核拒绝
                    case '2':
                        return that.$t('common.finReviewSuccess');// 财务审核通过
                    case '3':
                        return that.$t('common.colReviewing');// 催收审核中
                    case '4':
                        return that.$t('common.colReviewRefuse');// 催收审核拒绝
                    case '5':
                        return that.$t('common.colReviewSuccess');// 催收审核通过
                    default:
                        return '';
                }
            },
            //使用状态
            switchUsageStatus(status) {
                switch (status + '') {
                    case '0':
                        return that.$t('common.notTriggered');// 未触发
                    case '1':
                        return that.$t('common.notUsed');// 未使用
                    case '2':
                        return that.$t('common.hasUsed');// 已使用
                    case '3':
                        return that.$t('common.hasExpired');// 已过期
                    default:
                        return '';
                }
            }
        },
        created() {
            this.domain = this.$storage.get('user').domain
            this.showSpread = domain.showSpread();
            that = this;
            this.getTableData();
        }
    }
</script>
<style lang="scss" scoped>
    [data-page=collection-amountRemit-recordList] {
        .el-col {
            padding-left: 10px;
        }
        .el-table .cell, .el-table th > .cell {
            word-break: keep-all;
            word-wrap: break-word;
        }
    }
</style>

